package util;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;


public class ClientRequest {
	
	/* public static void main(String args[]) {

		    HttpClient client = new HttpClient();
		    client.getParams().setParameter("http.useragent", "Test Client");

		    BufferedReader br = null;

		    PostMethod method = new PostMethod("http://search.yahoo.com/search");
		    method.addParameter("p", "\"java2s\"");

		    try{
		      int returnCode = client.executeMethod(method);

		      if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
		        System.err.println("The Post method is not implemented by this URI");
		        // still consume the response body
		        method.getResponseBodyAsString();
		      } else {
		        br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
		        String readLine;
		        while(((readLine = br.readLine()) != null)) {
		          System.err.println(readLine);
		      }
		      }
		    } catch (Exception e) {
		      System.err.println(e);
		    } finally {
		      method.releaseConnection();
		      if(br != null) try { br.close(); } catch (Exception fe) {}
		    }

		  }*/

	public static void main1(String[] args){
		try{
			String uri = "http://demooauthmonkresource.elasticbeanstalk.com//DemoResourceServer?&client_id=riptide_client_id&client_secret=d58f814bd3ab9128ea5f1ea5264c5f&ap=HP.com&CALLBACKURI=http%3A%2F%2F127.0.0.1%3A8080%2F%2FMonkClient%2FStart.jsp&URL_AP_OTHER=http%3A%2F%2F127.0.0.1%3A8080%2FMonkAuthn%2FDemoAuthServer";
			
			uri = "http://localhost:8080/index.jsp";
			ClientRequest cr = new ClientRequest();
			System.out.println(cr.request(uri));
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
	}

	
	public String request(String uri)throws Exception{
		String result = null;
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httpreq = new HttpPost(uri);
		httpreq.setHeader("Content-Type",
				"application/x-www-form-urlencoded");

		// HttpParams params = new HttpParams();
		// httpreq.setParams(params);

		HttpResponse resp = httpclient.execute(httpreq);
		
		return result;
	}
}
